import Fenlei from "./fenlei.js"


import store from "../../store/store";



export default React.createClass({
	getInitialState(){
        return {
        	init :[]
        }
 }, 
 componentWillMount:function(){ 
        		store.dispatch(function(dispatch , state){
    fetch("http://www.chawo.com/mobile/index.php?act=brand&op=recommend_list")
                .then(res=>res.json())
                .then(data=>{
                    dispatch({
                        type : "FN_INIT",
                        content : data
                    })
                })
}) 
 }, 
 updateView(){ //此处为提供的更新视图方法
        var newData = store.getState(); 
        this.setState(
              {
              	init :newData.fenlist.goodslist
              }
        )
   },
   removeSubscribe : null,
    componentWillUnmount(){
        //组件即将被卸载  记得注销更新视图函数
        this.removeSubscribe();
    },
 componentDidMount:function(){
 	this.removeSubscribe= store.subscribe(this.updateView);
 	var that =this
// 	setInterval(function(){
// 		console.log(store.getState())
// 	},1000)
 },
	render : function(){
		 
		return  (
			<Fenlei data={this.state.init}/>
		)
	}
})
